﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Runtime.InteropServices;

namespace Woodlands
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class TimetableWindow : Page
    {

        public TimetableWindow()
        {
            InitializeComponent();
            webBrowser.Navigate("http://www.woodlandsuniversity.com/timetable-blank.php");
            var cal = System.Globalization.DateTimeFormatInfo.CurrentInfo.Calendar;
            DateTime firstDay = DateTime.Parse("19/09/2011");
            System.Globalization.CalendarWeekRule rule = System.Globalization.CalendarWeekRule.FirstDay;
            int i = 0;
            while (i < 52)
            {
                string W = "";
                if (cal.GetWeekOfYear(firstDay, rule, System.DayOfWeek.Monday).ToString() == "53")
                {
                    W = "1";
                }
                else
                {
                    W = cal.GetWeekOfYear(firstDay, rule, System.DayOfWeek.Monday).ToString();
                }
                dateSelector.Items.Add(W + firstDay.ToString(" - dd/MM/yy"));
                firstDay = cal.AddWeeks(firstDay, 1);
                if (cal.GetWeekOfYear(firstDay, rule, System.DayOfWeek.Monday).ToString() == cal.GetWeekOfYear(DateTime.Now, rule, System.DayOfWeek.Monday).ToString())
                {
                    dateSelector.SelectedIndex = i+1;
                }
                i++;
            }
        }

        private void IDTxt_KeyUp_1(object sender, KeyEventArgs e)
        {
            String ID = IDTxt.Text;
            int x = 0;
            try
            {
                x = int.Parse(ID);
            }
            catch(Exception numEx)
            {
                x = 0;
                Console.WriteLine(numEx.Data.ToString());
            }
            if (ID.Length >= 8)
            {
                String userType = "Student";
                if (x > 99000000)
                {
                    userType = "Staff";
                }
                webBrowser.Navigate("http://www.woodlandsuniversity.com/timetable-blank.php?uid=" + ID + "&ut=" + userType);
            }
            else
            {
                webBrowser.Navigate("http://www.woodlandsuniversity.com/timetable-blank.php");
            }
        }

        private void dateSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
    }
}
